package com.hptpd.questionnairesurvey.domain.question;

import com.google.common.collect.Lists;
import com.hptpd.questionnairesurvey.domain.Choice;
import com.hptpd.questionnairesurvey.domain.Dimensionality;
import com.hptpd.questionnairesurvey.domain.Questionnaire;
import com.hptpd.questionnairesurvey.domain.User;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* Date: 2019/9/11
 * \*
 * \* Description:
 * \
 *
 * @author walter_long
 */
@Entity
@Table(name = "question")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING, length = 20)
@Data
public class BaseQuestion {
    @Id
    @GenericGenerator(name = "uuid", strategy = "uuid")
    @GeneratedValue(generator = "uuid")
    @Column(name = "id")
    private String id;

    @Column(name = "topic")
    private String topic;

    @Column(name = "sort")
    private Integer sort;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dimensionality_id")
    private Dimensionality dimensionality;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "questionnaire_id")
    private Questionnaire questionnaire;

    @OneToMany(mappedBy = "baseQuestion", cascade = {CascadeType.PERSIST, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    private List<Choice> choices = Lists.newArrayList();
}
